<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <h1>jsonp跨域解决方案</h1>
    <!-- <input type="text" id="ipt"> -->
    <button id="btn">提交</button>
    <script>
        function callback(data){
            console.log("响应的数据是:",data);
        }
        // const oIpt = document.getElementById("ipt")
        const oBtn = document.getElementById("btn")
        oBtn.onclick = function(){
            // const oIptValue = oIpt.value
            // 创建script标签
            const oScript = document.createElement("script")
            //给script标签添加src属性(html中href/src可以跨域访问)
            //把回调函数的函数名放在路径上,以便后端获取
            oScript.src = "http://127.0.0.1:1234/user?id=123&cd=callback"
            //把节点追加到body上
            document.body.appendChild(oScript)
        }
    </script>
</body>
</html>